import java.util.*;
import java.io.*;

public class 三步必杀差分数列模板 {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static int n;
    public static void main(String[] args) throws IOException{
        n = in.nextInt();
        int q = in.nextInt();
        long[] arr = new long[n + 3];
        while(q-- > 0){
            int l = in.nextInt();
            int r = in.nextInt();
            int s = in.nextInt();
            int e = in.nextInt();
            int d = (e - s) / (r - l);
            set(l,r,s,e,d,arr);
        }
        build(arr);
        long xor = 0;
        long max = -0x3f3f3f3f;
        for (int i = 1; i <= n; i++) {
            xor ^= arr[i];
            max = Math.max(arr[i],max);
        }
        out.println(xor + " " + max);
        out.close();
    }

    private static void set(int l, int r, int s, int e, int d, long[] arr) {
        arr[l] += s;
        arr[l + 1] += d - s;
        arr[r + 1] -= d + e;
        arr[r + 2] += e;
    }
    private static void build(long[] arr){
        for (int i = 1; i <= n; i++) {
            arr[i] += arr[i - 1];
        }
        for (int i = 1; i <= n; i++) {
            arr[i] += arr[i - 1];
        }
    }
}
class Read // 自定义快速读入
{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException
    {
        while(!st.hasMoreTokens())
        {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException
    {
        return bf.readLine();
    }

    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException
    {
        return Double.parseDouble(next());
    }
}